package IO3;

import java.io.*;

/**
 * @description: IO_decoration01
 * 装饰模式 就像在管道外面再套一个加速管道
 * 处理流
 * 字节缓冲流
 * 在原先基础上加装饰 #27 #28
 * 套 BufferedInputStream()
 * 和 BufferedOutputStream()
 * 提高了性能
 * @date: 2019/12/17 19:31
 * @author: Vicuna
 */


public class IO_decoration01 {
    public static void main(String[] args) {
        //1 创建源
        File f = new File("E:/Code/Java练习/IO/src/IO2/aaa.txt");
        File d = new File("E:/Code/Java练习/IO/src/IO2/ccc.txt");
        //2 选择流
        InputStream is = null;
        OutputStream os = null;
        try {
            is =new BufferedInputStream(new FileInputStream(f)) ;
            os =new BufferedOutputStream(new FileOutputStream(d, false)) ;  //追加模式 每次运行在文件末尾追加
            //3 操作（写出）
            byte hc[] = new byte[3];      //缓冲容器
            int len = -1;                 //接收长度；
            while ((len = is.read(hc)) != -1) {
                os.write(hc, 0, len);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //4 释放 先打开 后关闭
            if (null != os) {
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (null != is) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
